@extends('develop.layoutEdit')

@section('title')

    @if(isset($flag) && $flag == 1)
        <li class="cur">
            <span>修改APP版本设置 </span>
        </li>
    @elseif( isset($flag) && $flag == 2)
        <li class="cur">
            <span>APP版本设置详情 </span>
        </li>
    @else
        <li class="cur">
            <span>添加APP版本设置 </span>
        </li>
    @endif

@endsection

@section('content')

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*&nbsp;</span>平台类型：</label>
        <div class="col-sm-6">
            <div class="layui-form">
                <input type="radio" name="appType" class="appType" value="2" title="android" @if( !isset($appType) || $appType == 2 ) checked @endif>&nbsp;&nbsp;
                <input type="radio" name="appType" class="appType" value="1" title="ios" @if( isset($appType) && $appType == 1 ) checked @endif>&nbsp;&nbsp;
            </div>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red mr5">*&nbsp;</span>版本code：</label>
        <div class="col-sm-6 form-inline">
            <input type="text" class="form-control"  style="width:250px;" id="appVersionCode" name="appVersionCode"  placeholder="请输入版本code" value="{{ $appVersionCode or ''}}">&nbsp;&nbsp;
            <span style="color:#999;">与客户端内部code保持一致</span>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red mr5">*&nbsp;</span>版本编号：</label>
        <div class="col-sm-6 form-inline">
            <input type="text" class="form-control"  style="width:250px;" id="appVersionNumber" name="appVersionNumber"  placeholder="请输入版本编号" value="{{ $appVersionNumber or ''}}">&nbsp;&nbsp;
            <span style="color:#999;">如：3.0.1</span>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red mr5">*&nbsp;</span>版本路径：</label>
        <div class="col-sm-6 form-inline">
            <input type="text" class="form-control"  style="width:400px;" id="apkPath" name="apkPath"  placeholder="请输入版本下载路径" value="{{ $apkPath or ''}}">&nbsp;&nbsp;
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*&nbsp;</span>是否强制升级：</label>
        <div class="col-sm-6">
            <div class="layui-form">
                <input type="radio" name="isMandatoryUpgrade"  value="0" title="否" @if( !isset($isMandatoryUpgrade) || $isMandatoryUpgrade == 0 ) checked @endif>&nbsp;&nbsp;
                <input type="radio" name="isMandatoryUpgrade"  value="1" title="是" @if( isset($isMandatoryUpgrade) && $isMandatoryUpgrade == 1 ) checked @endif>
            </div>
        </div>
    </div>

    <div class="form-group ">
        <label class="col-sm-3 control-label"><span class="red pr5">*&nbsp;</span>版本说明：</label>
        <div class="col-sm-6">
            <textarea name="appVersionExplain" class="form-control" id="appVersionExplain" rows="10"  placeholder="请输入版本说明">{{ $appVersionExplain or ''}}</textarea>
            <span style="color:#999;">版本说明行与行之间回车显示</span>
        </div>
    </div>

    <div class="form-group" id="edit">
        <label class="col-sm-3 control-label"></label>
        <div class="col-sm-9">
            <input type="hidden" name="appVersionId" id="appVersionId"  value="{{ $appVersionId or ''}}" >
            <input type="button"  value="保存" onclick="app.edit();" class="btn btn-success" >
        </div>
    </div>

@endsection

@section('js')
    <script>

        layui.use(['form'], function(){
            var form = layui.form();
        });
        var flag = {{$flag or 0}};
        //判断详情
        if ( flag == 2 ){  //详情
            $("form").find("input,textarea").attr("disabled", "disabled");
            $('#edit').hide();
        }

        if ( flag == 1 ) { //修改
            $('.appType').attr("disabled", "disabled");
            $('#appVersionCode').attr("disabled", "disabled");
            $('#appVersionNumber').attr("disabled", "disabled");
            $('#apkPath').attr("disabled", "disabled");
        }
        var app = {

            //保存
            edit:function () {

                var app_data = E.getFormValues('edit-form');
                var log ='';
                if (E.isEmpty(app_data.appVersionCode) ) {
                    log += '请输入版本code</br>';
                }

                if (E.isEmpty(app_data.appVersionNumber) ) {
                    log += '请输入版本编号</br>';
                }

                if (E.isEmpty(app_data.apkPath) ) {
                    log += '请输入版本下载路径</br>';
                }

                if (E.isEmpty(app_data.appVersionExplain) ) {
                    log += '请输入版本说明</br>';
                }

                if ( log ) {
                    layer.alert(log,{icon:2});
                    return false;
                }

                if ( app_data.appVersionId && app_data.appVersionId>0 ) {
                    var t = '您确认要修改该app版本设置吗';
                } else {
                    var t = '您确认要添加该app版本设置吗';
                }

                layer.confirm(t,{icon:3},function(index){

                    layer.close(index);
                    E.ajax({
                        type:'get',
                        url: '/lar/develop/app/store',
                        data: app_data,
                        dataType:'json',
                        // 返回值判断
                        success: function (obj) {
                            if ( obj.code == 200 ) {
                                layer.alert( obj.message , { icon: 1,time : 1500 } ) ;
                                parent.app.load();
                                setTimeout('E.layerClose();' ,1000 );
                            } else {
                                layer.alert(obj.message, {icon: 2});
                            }

                        }
                    });
                });

            }
        };

    </script>
@endsection